package org.zjt.hook;

import lombok.extern.slf4j.Slf4j;
import sun.misc.Signal;
import sun.misc.SignalHandler;

/**
 * Description:
 *
 * @author juntao.zhang
 * Date: 2018-12-01 12:04 PM
 * @see
 */
@Slf4j
public class JdkShutdownHook {


    public static void main(String[] args) {

        SignalHandler signalHandler = signal -> log.info("Signal Shutdown ....");

        Signal.handle(new Signal("INT"), signalHandler);
        Signal.handle(new Signal("TERM"), signalHandler);
        Signal.handle(new Signal("HUP"), signalHandler);


        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            log.info("JdkShutdownHook ....");
        }));


    }

}
